/**
 * 拦截response，统一返回｛code：200，data：data｝
 */

angular.module('imsApp')
    .config(['$httpProvider', function ($httpProvider) {
        $httpProvider.interceptors.push([function () {
            return {
                'request': function (config, body) {
                    var userInfo = JSON.parse(localStorage.getItem('userInfo'));
                    if(userInfo){
                        config.headers['X-Auth-Token'] = userInfo.token;
                    }else {
                        localStorage.removeItem("userInfo");
                        localStorage.setItem("orginUrl",window.location.href);
                        window.location = 'http://' + window.location.host;
                    }

                    return config;
                },
                response: function (response) {
                    if (response.hasOwnProperty('data')) {
                        if(response.data.c=="u"){
                            var userInfo = JSON.parse(localStorage.getItem('userInfo'));
                            localStorage.setItem("orginUser",userInfo.userName);
                            localStorage.setItem("orginUrl",window.location.href);

                            window.location = 'http://' + window.location.host;
                        }else{
                            return {code: response.status, data: response.data};

                        }

                    } else {
                        return response;
                    }
                }
            }
        }]);
    }]).value('api', "http://192.168.1.110:9010")
//     .config(['blockUIConfig', function (blockUIConfig) {
//   // 修改默认的提示信息
//   blockUIConfig.message = "加载中...";
//   // 修改UI不可见时默认的延迟时间为100ms
//   blockUIConfig.delay = 100;
//   // 禁用自动阻塞页面展示配置项
//   blockUIConfig.autoBlock = false;
// }])
